package logic.table;

import logic.constants.DefaultConsts;
import logic.util.logutil.LogUtil;
import android.provider.BaseColumns;


/**
 * 书架、书签、笔记
 * 
 * @author 刘宾
 * @date 2014年8月11日 上午10:46:48
 */
public class BooksTable
{
	
	public static final String table = "Books";
	
	public final class BookColums
	        implements
	        BaseColumns
	{
		public final static String ID                 = "id";
		public final static String STATUS             = "status";            //1本地书籍  2在线书籍 3 下载 4 推荐
		public final static String BOOK_ID            = "book_id";           //
		public final static String BOOK_NAME          = "book_name";
		public final static String BOOK_TYPE          = "book_type";         //1=图文书籍 2=流式杂志 3=连载 4=漫画 5=有声 6 板式杂志
		public final static String PATH               = "path";              //
		public final static String AUTHOR             = "author";            //
		public final static String CHAPTER_ID         = "chapter_id";        //
		public final static String WORD_INDEX         = "word_index";        //
		public final static String ACCOUNT            = "account";           //
		public final static String CREATE_TIME        = "create_time";       //
		public final static String LOGO_URL           = "logo_url";          //
		public final static String NCXURL             = "ncxUrl";            //目录下载url
		public final static String ISONLINE           = "isOnline";          //0|1:离线|在线
		public final static String SYNCSTATUS         = "syncStatus";            //0:未同步，1：同步,2:删除
		public final static String CHAPTER_NAME       = "chapterName";      //
		public final static String SERVER_ID          = "server_id";         //服务端的唯一id
		public final static String SERVER_CHAPTERID   = "server_chapterid";  //服务端的章节id
		public final static String STARTTIME   		  = "startTime";  //阅读开始时间
		public final static String ENDTIME   		  = "endTime";    //阅读结束时间
		
	}
	
	public static String getCreateTableSQL() {
		StringBuilder sb = new StringBuilder();
		sb.append("CREATE TABLE IF NOT EXISTS " + table + "(");
		
		sb.append(BookColums.ID + " INTEGER PRIMARY KEY AUTOINCREMENT,");
		sb.append(BookColums.STATUS + " INTEGER,");
		sb.append(BookColums.BOOK_ID + " INTEGER,");
		sb.append(BookColums.BOOK_NAME + " VARCHAR(50),");
		sb.append(BookColums.BOOK_TYPE + " INTEGER,");
		sb.append(BookColums.PATH + " TEXT,");
		sb.append(BookColums.AUTHOR + " VARCHAR(50),");
		sb.append(BookColums.CHAPTER_ID + " INTEGER,");
		sb.append(BookColums.WORD_INDEX + " INTEGER,");
		sb.append(BookColums.ACCOUNT + " VARCHAR(50),");
		sb.append(BookColums.CREATE_TIME + " VARCHAR(50),");
		sb.append(BookColums.LOGO_URL + " VARCHAR(50),");
		sb.append(BookColums.NCXURL + " VARCHAR(50),");
		sb.append(BookColums.ISONLINE + " INTEGER,");
		sb.append(BookColums.SYNCSTATUS + " INTEGER default 0,");
		sb.append(BookColums.CHAPTER_NAME + " VARCHAR(50),");
		sb.append(BookColums.SERVER_ID + " INTEGER default 0,");
		sb.append(BookColums.SERVER_CHAPTERID + " INTEGER,");
		sb.append(BookColums.STARTTIME + " INTEGER,");
		sb.append(BookColums.ENDTIME + " INTEGER");
		sb.append(");");
		LogUtil.d(DefaultConsts.TAG, table + ":" + sb.toString());
		return sb.toString();
	}

	/** 修复早期数据库添加Books表时，版本未升级的bug */
	public static String getOldTableSQL() {
		StringBuilder sb = new StringBuilder();
		sb.append("CREATE TABLE IF NOT EXISTS " + table + "(");
		
		sb.append(BookColums.ID + " INTEGER PRIMARY KEY AUTOINCREMENT,");
		sb.append(BookColums.STATUS + " INTEGER,");
		sb.append(BookColums.BOOK_ID + " INTEGER,");
		sb.append(BookColums.BOOK_NAME + " VARCHAR(50),");
		sb.append(BookColums.BOOK_TYPE + " INTEGER,");
		sb.append(BookColums.PATH + " TEXT,");
		sb.append(BookColums.AUTHOR + " VARCHAR(50),");
		sb.append(BookColums.CHAPTER_ID + " INTEGER,");
		sb.append(BookColums.WORD_INDEX + " INTEGER,");
		sb.append(BookColums.ACCOUNT + " VARCHAR(50),");
		sb.append(BookColums.CREATE_TIME + " VARCHAR(50),");
		sb.append(BookColums.LOGO_URL + " VARCHAR(50)");
		sb.append(");");
		LogUtil.d(DefaultConsts.TAG, table + ":" + sb.toString());
		return sb.toString();
	}
}
